package com.gxa.p2p.service.impl;

import com.gxa.p2p.mapper.InvestuserMapper;
import com.gxa.p2p.pojo.Borrowuser;
import com.gxa.p2p.pojo.Investuser;
import com.gxa.p2p.service.InvestuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Transactional(rollbackFor = {Throwable.class})
@Service("investuserService")
public class InvestuserServiceImpl implements InvestuserService {
    @Autowired
    InvestuserMapper investuserMapper;

    @Override
    public List<Map<String, Object>> count(String name, String phone, Boolean isReal, Boolean lockState, String from, Integer page, Integer size) {
        if (name !=null && name !=""){
            name = "%"+name+"%";
        }
        if (phone !=null && phone !=""){
            phone = "%"+phone+"%";
        }
        return investuserMapper.findInvestuserByPage(name, phone, isReal, lockState, from, null, null);
    }

    @Override
    public List<Map<String, Object>> findInvestuserByPage(String name, String phone, Boolean isReal, Boolean lockState, String from, Integer page, Integer size) {
        if (name !=null && name !=""){
            name = "%"+name+"%";
        }
        if (phone !=null && phone !=""){
            phone = "%"+phone+"%";
        }
        return investuserMapper.findInvestuserByPage(name, phone, isReal, lockState, from, (page-1)*size, size);
    }

    @Override
    public Investuser selectById(Long id) {
        return investuserMapper.selectById(id);
    }

    @Override
    public void updatePwd(Long id, String loginPwd, String dealPwd) {
        investuserMapper.updatePwd(id, loginPwd, dealPwd);
    }

    @Override
    public void updateInvestuser(Investuser investuser) {
        investuserMapper.updateInvestuser(investuser);
    }
}
